package com.zq.serviceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zq.comm.Const;
import com.zq.dao.DeptDao;
import com.zq.page.Page;
import com.zq.pojo.Dept;
import com.zq.service.DeptService;
@Service("DeptService")
public class DeptServiceImpl implements DeptService {
	@Autowired
	private DeptDao deptDao ;
	@Override
	public String add(Dept dept) {
		// TODO Auto-generated method stub
		String msg = Const.ERROR;
		try {
			deptDao.add(dept);
			msg = Const.SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return msg;
	}

	@Override
	public String delete(Dept dept) {
		String msg = Const.ERROR;
		try {
			deptDao.delete(dept);
			msg = Const.SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return msg;
	}

	@Override
	public String update(Dept dept) {
		String msg = Const.ERROR;
		try {
			deptDao.update(dept);
			msg = Const.SUCCESS;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return msg;
	}

	@Override
	public Dept findByDeptno(int deptNo) {
		// TODO Auto-generated method stub
		Dept dept = null;
		try {
			dept = deptDao.findByDeptno(deptNo);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return dept;
	}

	@Override
	public List<Dept> findAllDepts() {
		List<Dept> depts = new ArrayList<Dept>();;
		try {
			depts = deptDao.findAllDepts();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return depts;
	}

	@Override
	public List<Dept> findByDeptNames(String deptName) {
		List<Dept> depts = new ArrayList<Dept>();;
		try {
			depts = deptDao.findByDeptNames(deptName);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return depts;
	}

	@Override
	public List<Dept> findAll(int pageNo) {
		List<Dept> depts = new ArrayList<Dept>();
		try {
			depts = deptDao.findAll(pageNo);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return depts;
	}

	@Override
	public Page<Dept> getPage(int pageNo) {
		Page<Dept> page = null;
		try {
			page = deptDao.getPage(pageNo);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return page;
	}

	@Override
	public int getCount() {
		int in = 0;
		try {
			in = deptDao.getTotalNum();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return in;
	}

}
